export default {
  namespaced: true,
  state () {
    return {
      goodList: [
        {
          name: '诸葛亮',
          price: 1000,
          num: 1,
          checked: false
        },
        {
          name: '蔡文姬',
          price: 1500,
          num: 1,
          checked: false
        },
        {
          name: '妲己',
          price: 2000,
          num: 1,
          checked: false
        },
        {
          name: '鲁班',
          price: 2200,
          num: 1,
          checked: false
        }
      ]
    }
  },
  getters: {
    // 合计
    sumPrice (state) {
      return state.goodList.reduce((sum, item) => sum + item.price * item.num, 0)
    }
  },
  mutations: {
    changenum (state, payload) {
      state.goodList[payload.index].num = payload.num
    },
    removeList (state, payload) {
      state.goodList.splice(payload, 1)
    },
    UpdateChecked (state, payload) {
      state.goodList[payload].checked = !state.goodList[payload].checked
    },
    changeAll (state, payload) {
      // eslint-disable-next-line no-return-assign
      state.goodList.filter(item => item.checked).forEach(item => item.checked = payload)
    }

  },
  actions: {

  }
}
